package Java.BlackHorse.Regex;

public class RegexDemo2 {
    public static void main(String[] args) {
        //public boolean matches（String regex) :
        //判断是否与正则表达式匹配，若匹配返回true ，否则返回false

        //[abc]只能是a  b  c
        System.out.println("----------1----------");
        System.out.println("a".matches("[abc]"));//true
        System.out.println("z".matches("[abc]"));//false
        System.out.println("ab".matches("[abc]"));//false
        System.out.println("ab".matches("[abc][abc]"));//true

        //[^abc]  不是a b c
        System.out.println("----------2----------");
        System.out.println("a".matches("[^abc]"));//false
        System.out.println("z".matches("[^abc]"));//true
        System.out.println("zz".matches("[^abc]"));//false
        System.out.println("zz".matches("[^abc][^abc]"));//true

        //a 到 z A 到 Z [a-zA-Z
        System.out.println("----------3----------");
        System.out.println("a".matches("[a-zA-Z]"));//true
        System.out.println("z".matches("[a-zA-Z]"));//true
        System.out.println("zz".matches("[a-zA-Z]"));//false
        System.out.println("zz".matches("[a-zA-Z][a-zA-Z]"));//true
        System.out.println("0".matches("[a-zA-Z][a-zA-Z]"));//false
        System.out.println("0".matches("[a-zA-Z0-9]"));//true

        //[a-d[m-p]] a到d 或 m到p
        System.out.println("----------4----------");
        System.out.println("a".matches("[a-d[m-p]]"));//true
        System.out.println("z".matches("[a-d[m-p]]"));//false
        System.out.println("m".matches("[a-d[m-p]]"));//true
        System.out.println("p".matches("[a-d[m-p]]"));//true
        System.out.println("0".matches("[a-d[m-p]]"));//false

        //[a-z&&[def]] a到z 和 def 的交集
        System.out.println("----------5----------");
        System.out.println("a".matches("[a-z&&[def]]"));//false
        System.out.println("d".matches("[a-z&&[def]]"));//true
        System.out.println("f".matches("[a-z&&[def]]"));//true
        System.out.println("p".matches("[a-z&&[def]]"));//false
        System.out.println("0".matches("[a-z&&[def]]"));//false
        System.out.println("&".matches("[a-z&&[def]]"));//false

        //[a-z&&[^bc]] a到z (除了bc 等同于[ad-z])
        System.out.println("----------6----------");
        System.out.println("a".matches("[a-z&&[^bc]]"));//true
        System.out.println("b".matches("[a-z&&[^bc]]"));//false
        System.out.println("c".matches("[a-z&&[^bc]]"));//false
        System.out.println("d".matches("[a-z&&[^bc]]"));//true

        //[a-z&&[^m-p]] a到z (除了m到p)
        System.out.println("----------7----------");
        System.out.println("a".matches("[a-z&&[^m-p]]"));//true
        System.out.println("m".matches("[a-z&&[^m-p]]"));//false
        System.out.println("p".matches("[a-z&&[^m-p]]"));//false
        System.out.println("z".matches("[a-z&&[^m-p]]"));//true

    }
}
